<!DOCTYPE html>
<html lang="en">
	<head>
		<title>API Handler - Wave Framework</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width"/> 
		<link type="text/css" href="../style.css" rel="stylesheet" media="all"/>
		<link rel="icon" href="../../favicon.ico" type="image/x-icon"/>
		<link rel="icon" href="../../favicon.ico" type="image/vnd.microsoft.icon"/>
	</head>
	<body>
	
		<h1>API Handler</h1>
		
			<ul>
				<li><a href="#index-files">Files</a></li>
				<li><a href="#index-introduction">Introduction</a></li>
				<li><a href="#index-workflow">Workflow</a></li>
			</ul>
		
			<h2 id="index-files">Files</h2>
			
				<h3>/engine/handler.api.php</h3>
		
			<h2 id="index-introduction">Introduction</h2>
			
				<p>API Handler is loaded whenever a HTTP request is made to *.api extension. API Handler takes all the input from GET, POST, FILES; SESSION and COOKIE variables, loads Wave Framework API and sends all the input to the API and then returns the result to the user agent. By default the API Handler returns data in JSON format. It also loads <a href="database.htm">Database</a> class for additional functionality.</p>
			
			<h2 id="index-workflow">Workflow</h2>
			
				<p>This script can only be executed through <a href="gateway.htm">Index Gateway</a> and it throws a 403 Forbidden message if accessed directly.</p>
				
				<p>API Handler loads <a href="state.htm">State</a> Class and creates a new <a href="state.htm">State</a> object with the current configuration array. <a href="configuration.htm">Configuration</a> is required by the API.</p>
				
				<p>If database settings are set in configuration, then it also loads <a href="database.htm">Database</a> class and creates a new database object which is stored in <a href="state.htm">State</a>.</p>
				
				<p>API Handler also loads autoload script from either '/overrides/resources/scripts/script.php' or from '/resources/scripts/script.php', this file can include function definitions or other PHP-related functionality. It is only recommended to store additional functionality in Autoload script if absolutely necessary, such as for functions that are used by every <a href="guide_api.htm">API</a> call.</p>
				
				<p>API Handler loads <a href="api.htm">API</a> Class and creates a new API object with the current <a href="state.htm">State</a>.</p>
				
				<p>All input data from POST, GET, FILES and COOKIE arrays are merged into a single input array, which works similarly to $_REQUEST. Sessions are also started, if session cookie is detected. Session data is stored as 'www-session', but this is assigned by API itself and not by the handlers.</p>
				
				<p>If 'www-profile' is set in the input, then <a href="guide_api.htm">API</a> call is made using that profile and API will validate API profile by using the API profiles in /resources/api.profiles.ini file.</p>
				
				<p>API Handler sends a request to API. Wave Framework API object will validate the request, call all the required controllers, models and views and return data to user agent, if requested.</p>
				
				<p>API Handler also makes an entry in the log file about the request, if <a href="logger.htm">Logger</a> is used.</p>
			
	</body>
</html>